
// Notes:

// materials
// controling light position
// defining material properties

/* glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT0);
 glEnable(GL_DEPTH_TEST);
 glEnable(GL_NORMALIZE); */

/* GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
 GLfloat mat_shininess[] = { 50.0 };
 GLfloat light_position[] = { 2.0, 2.0, 2.0, 0.0 };
 GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
 GLfloat lmodel_ambient[] = { 0.1, 0.1, 0.1, 1.0 };
 
 glClearColor(0.0, 0.0, 0.0, 0.0);
 glShadeModel(GL_SMOOTH);
 
 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
 
 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
 glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
 glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
 
 glEnable(GL_LIGHTING);
 glEnable(GL_LIGHT0);
 glEnable(GL_DEPTH_TEST);
 glEnable(GL_NORMALIZE); */

#ifndef Velyn_Light_h
#define Velyn_Light_h

#include "Vector.h"

using namespace OhioState::Math;

namespace Velyn {

    class Light {

    private:
        
        // FIXME: make this a struct
        
        // union {
        //    float color[4];
        //    struct {
        //        float r, g, b, a;
        //    };
        // } ambient, diffuse, specular, position;
        
        float ambient[4];
        float diffuse[4];
        float specular[4];
        float shininess[1];
        float position[4];
        
        typedef struct {
            Vector4 ambient;
            Vector4 diffuse;
            Vector4 specular;
            float shininess;
            Vector4 position;
        } _Light;
        
        _Light light;
        
    public:
        
        Light() {
            light.ambient.setValue(0.5f, 0.5f, 0.5f, 1.0f);
            light.diffuse.setValue(0.5f, 0.5f, 0.5f, 1.0f);
            light.specular.setValue(0.5f, 0.5f, 0.5f, 1.0f);
            light.shininess = 100.f;
            light.position.setValue(1.0f, 0.0f, 1.0f, 0.0f);
        }
        
        ~Light() {}
        
        void enable() {
            glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            
            // glLightfv(GL_LIGHT0, GL_AMBIENT, ambient.getValue());
            glLightfv(GL_LIGHT0, GL_AMBIENT, light.ambient.getValue());
            glLightfv(GL_LIGHT0, GL_DIFFUSE, light.diffuse.getValue());
            glLightfv(GL_LIGHT0, GL_SPECULAR, light.specular.getValue());
            
            // FIXME: this wont work
            // glLightfv(GL_LIGHT0, GL_SHININESS, light.shininess);
            glLightfv(GL_LIGHT0, GL_POSITION, light.position.getValue());
        }
        
        void disable() {
            // glDisable(GL_LIGHTING);
            glDisable(GL_LIGHT0);
        }
    };
}

#endif
